/*
 * ComponentList.cpp
 *
 *  Created on: 2011-04-17
 *      Author: jacek
 */

#include "ComponentList.h"

ComponentList::ComponentList() {
	head=NULL;
}

ComponentList::~ComponentList() {
	while(head!=NULL){
		pom=head->next;
		delete head;
		head=pom;
	}
}
void ComponentList::Add(Component* component){
	if(component!=NULL){
		if(head==NULL){
			head=new ComponentElement(component);
		}else{
			pom=new ComponentElement(component);
			pom->next=head;
			head=pom;
		}
	}
	pom=NULL;
}
void ComponentList::Remove(Component* componet){
	ComponentElement* previous;
	pom=head;
	if(head->component==componet){
		head=head->next;
		delete pom;
	}
	else{
		while(pom!=NULL && pom->component!=componet){
			previous=pom;
			pom=pom->next;
		}

		if(pom!=NULL){
			previous->next=pom->next;
			delete pom;
		}
	}
	pom=NULL;
}
ComponentElement ComponentList::Begin(){
	return *head;
}
